<!doctype html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>TOML 语言规范 1.0 正式版 - 慧林淘友之达人助手</title>
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="referrer" content="no-referrer">
    <meta name="description" content="慧林淘友之达人助手:交流与建议、BUG反馈。">
    <meta property="og:site_name" content="慧林淘友之达人助手" />
    <meta property="og:locale" content="nn_NO" />
    <meta property="og:type" content="article" />
    <meta property="og:url" content="https://www.lyhuilin.com/posts/toml/" />
    <meta property="og:title" content="TOML 语言规范 1.0 正式版" />
    <meta property="og:image" content="https://www.lyhuilin.com/apple-touch-icon.png" />
    <meta property="og:description" content="慧林淘友之达人助手:交流与建议、BUG反馈。" />

    

    <meta property="twitter:title" content="TOML 语言规范 1.0 正式版" />
    <meta property="twitter:image" content="https://www.lyhuilin.com/apple-touch-icon.png" />
    <meta property="twitter:card" content="summary" />
    <meta property="twitter:description" content="慧林淘友之达人助手:交流与建议、BUG反馈。" />

    

    <link rel="canonical" href="https://www.lyhuilin.com/posts/toml/">

    <link href="//cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
          rel="stylesheet"
          integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
          crossorigin="anonymous" />

    <link rel="stylesheet" href="https://www.lyhuilin.com/css/main.css" />

    

    

    <link rel="shortcut icon"
          href="https://www.lyhuilin.com/favicon.ico">

    <link href='' rel="alternate" type="application/rss+xml" title="慧林淘友之达人助手" />
    <link href="//fonts.googleapis.com/css?family=Fira+Code|Merriweather+Sans:400,700|Merriweather:400,700&display=swap"
    rel="stylesheet">

<style>
    :root {
        --font-code: "Fira Code", monospace;
        --font-content: "Merriweather", serif;
        --font-title: "Merriweather Sans", sans-serif;
    }
</style>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?d4f2e101b391ba33a192c215809ef30f";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
  </head>

  <body>
    
  

<div class="my-4 my-md-5 header">
  <div class="container">
    <div class="row">
      <div class="col-auto offset-lg-1 d-none d-md-block">
        
          <a href="https://www.lyhuilin.com/">
            <img class="logo" src="https://www.lyhuilin.com/apple-touch-icon.png" alt="logo">
          </a>
        
      </div>
      <div class="col-auto align-self-center mr-auto">
        <a class="text-decoration-none" href="https://www.lyhuilin.com/">
          <h1 class="font-weight-bold name">
            慧林淘友之达人助手
          </h1>
        </a>

        <ul class="nav nav-primary">
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-home" href="/">
                
                Home
              </a>
            </li>
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-blog" href="https://3ae.cn">
                
                Blog
              </a>
            </li>
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-gitee" href="https://gitee.com/lyhuilin">
                
                Gitee
              </a>
            </li>
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-donations" href="/donations">
                
                Donations
              </a>
            </li>
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-Download" href="/download">
                
                Download
              </a>
            </li>
          
            <li class="nav-item">
              <a class="text-uppercase nav-link text-support" href="https://support.qq.com/products/65159">
                
                Support
              </a>
            </li>
          

          
        </ul>

        <ul class="nav nav-secondary">
          
        </ul>
      </div>
    </div>
  </div>
</div>


  <div class="content">
    <div class="container">
      <div class="row justify-content-center">
        <div class="col-md-12 col-lg-10">
          <h1 class="mx-0 mx-md-4">
            TOML 语言规范 1.0 正式版
          </h1>
          <div class="markdown">
            
  <p>👉 TOML 语言广泛用于 Rust 项目当中，cargo new 一个新项目时都会新建一个 toml 的配置文件，所以学习 Rust 过程中也有必要熟悉 TOML 语言的相关语法，从而熟练在 Rust 项目中编辑配置文件。</p>
<p>👉 本文来自 <a href="https://github.com/toml-lang/toml.io">toml-lang 的中文翻译版本</a>，本文收录在此处，只是方便 Rust 学习者统一查阅，若是发现有任何错误或需要完善地方，请在 toml.io 原项目仓库指出或修改错误。</p>
<h1 id="toml-v100">TOML v1.0.0</h1>
<p>全称：Tom 的（语义）明显、（配置）最小化的语言。（Tom&rsquo;s Obvious, Minimal Language）<br>
作者：Tom Preston-Werner、Pradyun Gedam 等人。</p>
<h3 id="宗旨">宗旨</h3>
<p>TOML 旨在成为一个语义明显且易于阅读的最小化配置文件格式。<br>
TOML 被设计成可以无歧义地映射为哈希表。<br>
TOML 应该能很容易地被解析成各种语言中的数据结构。</p>
<h3 id="目录">目录</h3>
<ul>
<li><a href="#%E8%A7%84%E6%A0%BC">规格</a></li>
<li><a href="#%E6%B3%A8%E9%87%8A">注释</a></li>
<li><a href="#%E9%94%AE%E5%80%BC%E5%AF%B9">键值对</a></li>
<li><a href="#%E9%94%AE%E5%90%8D">键名</a></li>
<li><a href="#%E5%AD%97%E7%AC%A6%E4%B8%B2">字符串</a></li>
<li><a href="#%E6%95%B4%E6%95%B0">整数</a></li>
<li><a href="#%E6%B5%AE%E7%82%B9%E6%95%B0">浮点数</a></li>
<li><a href="#%E5%B8%83%E5%B0%94%E5%80%BC">布尔值</a></li>
<li><a href="#%E5%9D%90%E6%A0%87%E6%97%A5%E6%9C%9F%E6%97%B6%E5%88%BB">坐标日期时刻</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%A5%E6%9C%9F%E6%97%B6%E5%88%BB">各地日期时刻</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%A5%E6%9C%9F">各地日期</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%B6%E5%88%BB">各地时刻</a></li>
<li><a href="#%E6%95%B0%E7%BB%84">数组</a></li>
<li><a href="#%E8%A1%A8">表</a></li>
<li><a href="#%E5%86%85%E8%81%94%E8%A1%A8">内联表</a></li>
<li><a href="#%E8%A1%A8%E6%95%B0%E7%BB%84">表数组</a></li>
<li><a href="#%E6%96%87%E4%BB%B6%E6%89%A9%E5%B1%95%E5%90%8D">文件扩展名</a></li>
<li><a href="#mime-%E7%B1%BB%E5%9E%8B">MIME 类型</a></li>
<li><a href="#abnf-%E8%AF%AD%E6%B3%95">ABNF 语法</a></li>
</ul>
<h3 id="规格">规格</h3>
<ul>
<li>TOML 是大小写敏感的。</li>
<li>TOML 文件必须是合法的 UTF-8 编码的 Unicode 文档。</li>
<li>空白是指制表符（0x09）或空格（0x20）。</li>
<li>换行是指 LF（0x0A）或 CRLF（0x0D0A）。</li>
</ul>
<h3 id="注释">注释</h3>
<p>井字符将该行余下的部分标记为注释，除非它在字符串中。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 这是一个全行注释</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">key</span> = <span style="color:#e6db74">&#34;value&#34;</span>  <span style="color:#75715e"># 这是一个行末注释</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">another</span> = <span style="color:#e6db74">&#34;# 这不是一个注释&#34;</span>
</span></span></code></pre></div><p>除制表符以外的控制字符（U+0000 至 U+0008，U+000A 至 U+001F，U+007F）不允许出现在注释中。</p>
<h3 id="键值对">键值对</h3>
<p>TOML 文档最基本的构成区块是键值对。</p>
<p>键名在等号的左边而值在右边。<br>
键名和键值周围的空白会被忽略。<br>
键、等号和值必须在同一行（不过有些值可以跨多行）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">key</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span></code></pre></div><p>值必须是下述类型之一。</p>
<ul>
<li><a href="#%E5%AD%97%E7%AC%A6%E4%B8%B2">字符串</a></li>
<li><a href="#%E6%95%B4%E6%95%B0">整数</a></li>
<li><a href="#%E6%B5%AE%E7%82%B9%E6%95%B0">浮点数</a></li>
<li><a href="#%E5%B8%83%E5%B0%94%E5%80%BC">布尔值</a></li>
<li><a href="#%E5%9D%90%E6%A0%87%E6%97%A5%E6%9C%9F%E6%97%B6%E5%88%BB">坐标日期时刻</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%A5%E6%9C%9F%E6%97%B6%E5%88%BB">各地日期时刻</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%A5%E6%9C%9F">各地日期</a></li>
<li><a href="#%E5%90%84%E5%9C%B0%E6%97%B6%E5%88%BB">各地时刻</a></li>
<li><a href="#%E6%95%B0%E7%BB%84">数组</a></li>
<li><a href="#%E5%86%85%E8%81%94%E8%A1%A8">内联表</a></li>
</ul>
<p>不指定值是非法的。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">key</span> = <span style="color:#75715e"># 非法</span>
</span></span></code></pre></div><p>键值对后必须换行（或结束文件）。<br>
（例外见<a href="#%E5%86%85%E8%81%94%E8%A1%A8">内联表</a>）</p>
<pre tabindex="0"><code>first = &#34;Tom&#34; last = &#34;Preston-Werner&#34; # 非法
</code></pre><h3 id="键名">键名</h3>
<p>键名可以是裸露的，引号引起来的，或点分隔的。</p>
<p><strong>裸键</strong>只能包含 ASCII 字母，ASCII 数字，下划线和短横线（<code>A-Za-z0-9_-</code>）。<br>
注意裸键允许仅由纯 ASCII 数字构成，例如 <code>1234</code>，但是是被理解为字符串的。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">key</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">bare_key</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">bare-key</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">1234</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span></code></pre></div><p><strong>引号键</strong>遵循与基本字符串或字面量字符串相同的规则并允许你使用更为广泛的键名。<br>
除非明显必要，使用裸键方为最佳实践。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#e6db74">&#34;127.0.0.1&#34;</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#34;character encoding&#34;</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#34;ʎǝʞ&#34;</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;key2&#39;</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;quoted &#34;value&#34;&#39;</span> = <span style="color:#e6db74">&#34;value&#34;</span>
</span></span></code></pre></div><p>裸键中不能为空，但空引号键是允许的（虽然不建议如此）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>= <span style="color:#e6db74">&#34;no key name&#34;</span>  <span style="color:#75715e"># 非法</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#34;&#34;</span> = <span style="color:#e6db74">&#34;blank&#34;</span>     <span style="color:#75715e"># 合法但不鼓励</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;&#39;</span> = <span style="color:#e6db74">&#39;blank&#39;</span>     <span style="color:#75715e"># 合法但不鼓励</span>
</span></span></code></pre></div><p><strong>点分隔键</strong>是一系列通过点相连的裸键或引号键。<br>
这允许了你将相近属性放在一起：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Orange&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">physical</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;orange&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">physical</span>.<span style="color:#a6e22e">shape</span> = <span style="color:#e6db74">&#34;round&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">site</span>.<span style="color:#e6db74">&#34;google.com&#34;</span> = <span style="color:#66d9ef">true</span>
</span></span></code></pre></div><p>等价于 JSON 的如下结构：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Orange&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;physical&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;color&#34;</span>: <span style="color:#e6db74">&#34;orange&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;shape&#34;</span>: <span style="color:#e6db74">&#34;round&#34;</span>
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;site&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;google.com&#34;</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>有关点分隔键定义表的详细信息，请参阅后文<a href="#%E8%A1%A8">表</a>一节。</p>
<p>点分隔符周围的空白会被忽略。<br>
不过，最佳实践是不要使用任何不必要的空白。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;banana&#34;</span>     <span style="color:#75715e"># 这是最佳实践</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">fruit</span>. <span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;yellow&#34;</span>    <span style="color:#75715e"># 等同于 fruit.color</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">fruit</span> . <span style="color:#a6e22e">flavor</span> = <span style="color:#e6db74">&#34;banana&#34;</span>   <span style="color:#75715e"># 等同于 fruit.flavor</span>
</span></span></code></pre></div><p>缩进被作为空白对待而被忽略。</p>
<p>多次定义同一个键是非法的。</p>
<pre tabindex="0"><code># 不要这样做
name = &#34;Tom&#34;
name = &#34;Pradyun&#34;
</code></pre><p>注意裸键和引号键是等价的：</p>
<pre tabindex="0"><code># 这是不可行的
spelling = &#34;favorite&#34;
&#34;spelling&#34; = &#34;favourite&#34;
</code></pre><p>只要一个键还没有被直接定义过，你就仍可以对它和它下属的键名赋值。</p>
<pre tabindex="0"><code># 这使“fruit”键作为表存在。
fruit.apple.smooth = true

# 所以接下来你可以像中这样对“fruit”表添加内容：
fruit.orange = 2
</code></pre><pre tabindex="0"><code># 以下是非法的

# 这将 fruit.apple 的值定义为一个整数。
fruit.apple = 1

# 但接下来这将 fruit.apple 像表一样对待了。
# 整数不能变成表。
fruit.apple.smooth = true
</code></pre><p>不鼓励跳跃式地定义点分隔键。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 合法但不鼓励</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">type</span> = <span style="color:#e6db74">&#34;水果&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">type</span> = <span style="color:#e6db74">&#34;水果&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">skin</span> = <span style="color:#e6db74">&#34;薄&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">skin</span> = <span style="color:#e6db74">&#34;厚&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;红&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;橙&#34;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 建议</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">type</span> = <span style="color:#e6db74">&#34;水果&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">skin</span> = <span style="color:#e6db74">&#34;薄&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;红&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">type</span> = <span style="color:#e6db74">&#34;水果&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">skin</span> = <span style="color:#e6db74">&#34;厚&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">orange</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;红&#34;</span>
</span></span></code></pre></div><p>由于裸键可以仅由 ASCII 整数组成，所以可能写出看起来像浮点数、但实际上是两部分的点分隔键。<br>
除非你有充分的理由（基本不太会），否则不要这样做。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#ae81ff">3.14159</span> = <span style="color:#e6db74">&#34;派&#34;</span>
</span></span></code></pre></div><p>上面的 TOML 对应以下 JSON。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{ <span style="color:#f92672">&#34;3&#34;</span>: { <span style="color:#f92672">&#34;14159&#34;</span>: <span style="color:#e6db74">&#34;派&#34;</span> } }
</span></span></code></pre></div><h3 id="字符串">字符串</h3>
<p>共有四种方式来表示字符串：基本字符串、多行基本字符串、字面量和多行字面量。<br>
所有字符串都只能包含有效的 UTF-8 字符。</p>
<p><strong>基本字符串</strong>由引号（<code>&quot;</code>）包裹。<br>
任何 Unicode 字符都可以使用，除了那些必须转义的：引号，反斜杠，以及除制表符外的控制字符（U+0000 至 U+0008，U+000A 至 U+001F，U+007F）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">str</span> = <span style="color:#e6db74">&#34;我是一个字符串。\&#34;你可以把我引起来\&#34;。姓名\tJos\u00E9\n位置\t旧金山。&#34;</span>
</span></span></code></pre></div><p>为了方便，一些流行的字符有其简便转义写法。</p>
<pre tabindex="0"><code>\b         - backspace       (U+0008)
\t         - tab             (U+0009)
\n         - linefeed        (U+000A)
\f         - form feed       (U+000C)
\r         - carriage return (U+000D)
\&#34;         - quote           (U+0022)
\\         - backslash       (U+005C)
\uXXXX     - unicode         (U+XXXX)
\UXXXXXXXX - unicode         (U+XXXXXXXX)
</code></pre><p>任何 Unicode 字符都可以用 <code>\uXXXX</code> 或 <code>\UXXXXXXXX</code> 的形式来转义。<br>
转义码必须是有效的 Unicode <a href="https://unicode.org/glossary/#unicode_scalar_value">标量值</a>。</p>
<p>所有上面未列出的其它转义序列都是保留的；如果用了，TOML 应当产生错误。</p>
<p>有时你需要表示一小篇文本（例如译文）或者想要对非常长的字符串进行折行。<br>
TOML 对此进行了简化。</p>
<p><strong>多行基本字符串</strong>由三个引号包裹，允许折行。<br>
紧随开头引号的那个换行会被去除。<br>
其它空白和换行会被原样保留。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">str1</span> = <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Roses are red
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">Violets are blue&#34;&#34;&#34;</span>
</span></span></code></pre></div><p>TOML 解析器可以相对灵活地解析成对所在平台有效的换行字符。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 在 Unix 系统，上面的多行字符串可能等同于：</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str2</span> = <span style="color:#e6db74">&#34;Roses are red\nViolets are blue&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 在 Windows 系统，它可能等价于：</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str3</span> = <span style="color:#e6db74">&#34;Roses are red\r\nViolets are blue&#34;</span>
</span></span></code></pre></div><p>想书写长字符串却不想引入无关空白，可以用“行末反斜杠”。<br>
当一行的最后一个非空白字符是未被转义的 <code>\</code> 时，它会连同它后面的所有空白（包括换行）一起被去除，直到下一个非空白字符或结束引号为止。<br>
所有对基本字符串有效的转义序列，对多行基本字符串也同样适用。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 下列字符串的每一个字节都完全相同：</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str1</span> = <span style="color:#e6db74">&#34;The quick brown fox jumps over the lazy dog.&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str2</span> = <span style="color:#e6db74">&#34;&#34;&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">The quick brown \
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  fox jumps over \
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    the lazy dog.&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str3</span> = <span style="color:#e6db74">&#34;&#34;&#34;\
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">       The quick brown \
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">       fox jumps over \
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">       the lazy dog.\
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">       &#34;&#34;&#34;</span>
</span></span></code></pre></div><p>任何 Unicode 字符都可以使用，除了那些必须被转义的：反斜杠和除制表符、换行符、回车符外的控制字符（U+0000 至 U+0008，U+000B，U+000C，U+000E 至 U+001F，U+007F）。</p>
<p>你可以在多行基本字符串内的任何地方写一个引号或两个毗连的引号。<br>
它们也可以写在紧邻界分符内的位置。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">str4</span> = <span style="color:#e6db74">&#34;&#34;&#34;这有两个引号：&#34;&#34;。够简单。&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># str5 = &#34;&#34;&#34;这有两个引号：&#34;&#34;&#34;。&#34;&#34;&#34;  # 非法</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str5</span> = <span style="color:#e6db74">&#34;&#34;&#34;这有三个引号：&#34;&#34;\&#34;。&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str6</span> = <span style="color:#e6db74">&#34;&#34;&#34;这有十五个引号：&#34;&#34;\&#34;&#34;&#34;\&#34;&#34;&#34;\&#34;&#34;&#34;\&#34;&#34;&#34;\&#34;。&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># &#34;这，&#34;她说，&#34;只是个无意义的条款。&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str7</span> = <span style="color:#e6db74">&#34;&#34;&#34;&#34;</span><span style="color:#960050;background-color:#1e0010">这，</span><span style="color:#e6db74">&#34;她说，&#34;</span><span style="color:#960050;background-color:#1e0010">只是个无意义的条款。</span><span style="color:#e6db74">&#34;&#34;&#34;&#34;</span>
</span></span></code></pre></div><p>如果你常常要指定 Windows 路径或正则表达式，那么必须转义反斜杠就马上成为啰嗦而易错的了。<br>
为了帮助搞定这点，TOML 支持字面量字符串，它完全不允许转义。</p>
<p><strong>字面量字符串</strong>由单引号包裹。<br>
类似于基本字符串，他们只能表现为单行：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 所见即所得。</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">winpath</span>  = <span style="color:#e6db74">&#39;C:\Users\nodejs\templates&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">winpath2</span> = <span style="color:#e6db74">&#39;\\ServerX\admin$\system32\&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">quoted   = &#39;</span><span style="color:#a6e22e">Tom</span> <span style="color:#e6db74">&#34;Dubs&#34;</span> <span style="color:#a6e22e">Preston-Werner</span><span style="color:#e6db74">&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">regex    = &#39;</span><span style="color:#960050;background-color:#1e0010">&lt;\</span><span style="color:#a6e22e">i</span><span style="color:#960050;background-color:#1e0010">\</span><span style="color:#a6e22e">c</span><span style="color:#960050;background-color:#1e0010">*\</span><span style="color:#a6e22e">s</span><span style="color:#960050;background-color:#1e0010">*&gt;&#39;</span>
</span></span></code></pre></div><p>由于没有转义，无法在由单引号包裹的字面量字符串中写入单引号。<br>
万幸，TOML 支持一种多行版本的字面量字符串来解决这个问题。</p>
<p><strong>多行字面量字符串</strong>两侧各有三个单引号来包裹，允许换行。<br>
类似于字面量字符串，无论任何转义都不存在。<br>
紧随开始标记的那个换行会被剔除。<br>
开始结束标记之间的所有其它内容会原样对待。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">regex2</span> = <span style="color:#e6db74">&#39;&#39;&#39;I [dw]on&#39;</span><span style="color:#a6e22e">t</span> <span style="color:#a6e22e">need</span> <span style="color:#960050;background-color:#1e0010">\</span><span style="color:#a6e22e">d</span>{<span style="color:#ae81ff">2</span>} <span style="color:#a6e22e">apples</span><span style="color:#e6db74">&#39;&#39;&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">lines  = &#39;&#39;&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">原始字符串中的</span>
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">第一个换行被剔除了。</span>
</span></span><span style="display:flex;"><span>   <span style="color:#960050;background-color:#1e0010">所有其它空白</span>
</span></span><span style="display:flex;"><span>   <span style="color:#960050;background-color:#1e0010">都保留了。</span>
</span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;&#39;</span><span style="color:#960050;background-color:#1e0010">&#39;</span>
</span></span></code></pre></div><p>你可以在多行字面量字符串中的任何位置写一个或两个单引号，但三个以上的单引号序列不可以。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">quot15</span> = <span style="color:#e6db74">&#39;&#39;&#39;这有十五个引号：&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#39;&#39;&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># apos15 = &#39;&#39;&#39;这有十五个撇号：&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;  # 非法</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apos15</span> = <span style="color:#e6db74">&#34;这有十五个撇号：&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#39;&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># &#39;那，&#39;她说，&#39;仍然没有意义。&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">str</span> = <span style="color:#e6db74">&#39;&#39;&#39;&#39;</span><span style="color:#960050;background-color:#1e0010">那，</span><span style="color:#e6db74">&#39;她说，&#39;</span><span style="color:#960050;background-color:#1e0010">仍然没有意义。</span><span style="color:#e6db74">&#39;&#39;&#39;&#39;</span>
</span></span></code></pre></div><p>除制表符以外的所有控制字符都不允许出现在字面量字符串中。<br>
因此，对于二进制数据，建议你使用 Base64 或其它合适的 ASCII 或 UTF-8 编码。<br>
对那些编码的处理方式，将交由应用程序自己来确定。</p>
<h3 id="整数">整数</h3>
<p>整数是纯数字。<br>
正数可以有加号前缀。<br>
负数的前缀是减号。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">int1</span> = <span style="color:#ae81ff">+99</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int2</span> = <span style="color:#ae81ff">42</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int3</span> = <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int4</span> = <span style="color:#ae81ff">-17</span>
</span></span></code></pre></div><p>对于大数，你可以在数字之间用下划线来增强可读性。<br>
每个下划线两侧必须至少有一个数字。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">int5</span> = <span style="color:#ae81ff">1_000</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int6</span> = <span style="color:#ae81ff">5_349_221</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int7</span> = <span style="color:#ae81ff">53_49_221</span>  <span style="color:#75715e"># 印度记数体系分组</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">int8</span> = <span style="color:#ae81ff">1_2_3_4_5</span>  <span style="color:#75715e"># 合法但不鼓励</span>
</span></span></code></pre></div><p>前导零是不允许的。<br>
整数值 <code>-0</code> 与 <code>+0</code> 是有效的，并等同于无前缀的零。</p>
<p>非负整数值也可以用十六进制、八进制或二进制来表示。<br>
在这些格式中，<code>+</code> 不被允许，而（前缀后的）前导零是允许的。<br>
十六进制值大小写不敏感。<br>
数字间的下划线是允许的（但不能存在于前缀和值之间）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 带有 `0x` 前缀的十六进制</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">hex1</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">xDEADBEEF</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">hex2</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">xdeadbeef</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">hex3</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">xdead_beef</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 带有 `0o` 前缀的八进制</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">oct1</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">o01234567</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">oct2</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">o755</span> <span style="color:#75715e"># 对于表示 Unix 文件权限很有用</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 带有 `0b` 前缀的二进制</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">bin1</span> = <span style="color:#ae81ff">0</span><span style="color:#a6e22e">b11010110</span>
</span></span></code></pre></div><p>任何 64 位有符号整数（从 −2^63 到 2^63−1）都应当被接受并无损处理。<br>
如果无法无损表现某个整数，则必须抛出错误。</p>
<h3 id="浮点数">浮点数</h3>
<p>浮点数应当被实现为 IEEE 754 binary64 值。</p>
<p>一个浮点数由一个整数部分（遵从与十进制整数值相同的规则）后跟上一个小数部分和/或一个指数部分组成。<br>
如果小数部分和指数部分兼有，那小数部分必须在指数部分前面。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 小数</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt1</span> = <span style="color:#ae81ff">+1.0</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt2</span> = <span style="color:#ae81ff">3.1415</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt3</span> = <span style="color:#ae81ff">-0.01</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 指数</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt4</span> = <span style="color:#ae81ff">5</span><span style="color:#a6e22e">e</span><span style="color:#ae81ff">+22</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt5</span> = <span style="color:#ae81ff">1</span><span style="color:#a6e22e">e06</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt6</span> = <span style="color:#ae81ff">-2</span><span style="color:#a6e22e">E-2</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 都有</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">flt7</span> = <span style="color:#ae81ff">6.626</span><span style="color:#a6e22e">e-34</span>
</span></span></code></pre></div><p>小数部分是一个小数点后跟一个或多个数字。</p>
<p>一个指数部分是一个 E（大小写均可）后跟一个整数部分（遵从与十进制整数值相同的规则，但可以包含前导零）。</p>
<p>小数点，如果有用到的话，每侧必须紧邻至少一个数字。</p>
<pre tabindex="0"><code># 非法的浮点数
invalid_float_1 = .7
invalid_float_2 = 7.
invalid_float_3 = 3.e+20
</code></pre><p>与整数相似，你可以使用下划线来增强可读性。<br>
每个下划线必须被至少一个数字围绕。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">flt8</span> = <span style="color:#ae81ff">224_617.445</span><span style="color:#a6e22e">_991_228</span>
</span></span></code></pre></div><p>浮点数值 <code>-0.0</code> 与 <code>+0.0</code> 是有效的，并且应当遵从 IEEE 754。</p>
<p>特殊浮点值也能够表示。<br>
它们是小写的。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 无穷</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf1</span> = <span style="color:#a6e22e">inf</span>  <span style="color:#75715e"># 正无穷</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf2</span> = <span style="color:#960050;background-color:#1e0010">+</span><span style="color:#a6e22e">inf</span> <span style="color:#75715e"># 正无穷</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf3</span> = <span style="color:#a6e22e">-inf</span> <span style="color:#75715e"># 负无穷</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 非数</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf4</span> = <span style="color:#a6e22e">nan</span>  <span style="color:#75715e"># 实际上对应信号非数码还是静默非数码，取决于实现</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf5</span> = <span style="color:#960050;background-color:#1e0010">+</span><span style="color:#a6e22e">nan</span> <span style="color:#75715e"># 等同于 `nan`</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sf6</span> = <span style="color:#a6e22e">-nan</span> <span style="color:#75715e"># 有效，实际码取决于实现</span>
</span></span></code></pre></div><h3 id="布尔值">布尔值</h3>
<p>布尔值就是你所惯用的那样。<br>
要小写。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">bool1</span> = <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">bool2</span> = <span style="color:#66d9ef">false</span>
</span></span></code></pre></div><h3 id="坐标日期时刻">坐标日期时刻</h3>
<p>要准确地表示世上的一个特定时间，你可以使用指定了时区偏移量的 <a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a> 格式的日期时刻。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">odt1</span> = <span style="color:#e6db74">1979-05-27T07:32:00Z</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">odt2</span> = <span style="color:#e6db74">1979-05-27T00:32:00-07:00</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">odt3</span> = <span style="color:#ae81ff">1979-05-27</span><span style="color:#a6e22e">T00</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00.999999</span><span style="color:#ae81ff">-07</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00</span>
</span></span></code></pre></div><p>出于可读性的目的，你可以用一个空格字符替代日期和时刻之间的 T（RFC 3339 的第 5.6 节中允许了这样做）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">odt4</span> = <span style="color:#ae81ff">1979-05-27</span> <span style="color:#ae81ff">07</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00</span><span style="color:#a6e22e">Z</span>
</span></span></code></pre></div><p>毫秒级的精度是必须的。<br>
更高精度的小数秒取决于实现。<br>
如果它的值超出了实现所支持的精度，那超出的部分必须被舍弃，而不能四舍五入。</p>
<h3 id="各地日期时刻">各地日期时刻</h3>
<p>如果你省略了 <a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a> 日期时刻中的时区偏移量，这表示该日期时刻的使用并不涉及时区偏移。<br>
在没有其它信息的情况下，并不知道它究竟该被转化成世上的哪一刻。<br>
如果仍被要求转化，那结果将取决于实现。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">ldt1</span> = <span style="color:#ae81ff">1979-05-27</span><span style="color:#a6e22e">T07</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ldt2</span> = <span style="color:#ae81ff">1979-05-27</span><span style="color:#a6e22e">T00</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00.999999</span>
</span></span></code></pre></div><p>毫秒级的精度是必须的。<br>
更高精度的小数秒取决于实现。<br>
如果它的值超出了实现所支持的精度，那多余的部分必须被舍弃，而不能四舍五入。</p>
<h3 id="各地日期">各地日期</h3>
<p>如果你只写了 <a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a> 日期时刻中的日期部分，那它表示一整天，同时也不涉及时区偏移。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">ld1</span> = <span style="color:#ae81ff">1979-05-27</span>
</span></span></code></pre></div><h3 id="各地时刻">各地时刻</h3>
<p>如果你只写了 <a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a> 日期时刻中的时刻部分，它将只表示一天之中的那个时刻，而与任何特定的日期无关、亦不涉及时区偏移。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">lt1</span> = <span style="color:#ae81ff">07</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">lt2</span> = <span style="color:#ae81ff">00</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">32</span><span style="color:#960050;background-color:#1e0010">:</span><span style="color:#ae81ff">00.999999</span>
</span></span></code></pre></div><p>毫秒级的精度是必须的。<br>
更高精度的小数秒取决于实现。<br>
如果它的值超出了实现所支持的精度，那多余的部分必须被舍弃，而不能四舍五入。</p>
<h3 id="数组">数组</h3>
<p>数组是内含值的方括号。<br>
空白会被忽略。<br>
子元素由逗号分隔。<br>
数组可以包含与键值对所允许的相同数据类型的值。<br>
可以混合不同类型的值。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">integers</span> = [ <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">3</span> ]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">colors</span> = [ <span style="color:#e6db74">&#34;红&#34;</span>, <span style="color:#e6db74">&#34;黄&#34;</span>, <span style="color:#e6db74">&#34;绿&#34;</span> ]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">nested_array_of_ints</span> = [ [ <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span> ], [<span style="color:#ae81ff">3</span>, <span style="color:#ae81ff">4</span>, <span style="color:#ae81ff">5</span>] ]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">nested_mixed_array</span> = [ [ <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span> ], [<span style="color:#e6db74">&#34;a&#34;</span>, <span style="color:#e6db74">&#34;b&#34;</span>, <span style="color:#e6db74">&#34;c&#34;</span>] ]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">string_array</span> = [ <span style="color:#e6db74">&#34;所有的&#34;</span>, <span style="color:#e6db74">&#39;字符串&#39;</span>, <span style="color:#e6db74">&#34;&#34;&#34;是相同的&#34;&#34;&#34;</span>, <span style="color:#e6db74">&#39;&#39;&#39;类型&#39;&#39;&#39;</span> ]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 允许混合类型的数组</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">numbers</span> = [ <span style="color:#ae81ff">0.1</span>, <span style="color:#ae81ff">0.2</span>, <span style="color:#ae81ff">0.5</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">5</span> ]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">contributors</span> = [
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;Foo Bar &lt;foo@example.com&gt;&#34;</span>,
</span></span><span style="display:flex;"><span>  { <span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Baz Qux&#34;</span>, <span style="color:#a6e22e">email</span> = <span style="color:#e6db74">&#34;bazqux@example.com&#34;</span>, <span style="color:#a6e22e">url</span> = <span style="color:#e6db74">&#34;https://example.com/bazqux&#34;</span> }
</span></span><span style="display:flex;"><span>]
</span></span></code></pre></div><p>数组可以跨行。<br>
数组的最后一个值后面可以有终逗号（也称为尾逗号）。<br>
值、逗号、结束括号前可以存在任意数量的换行和注释。<br>
数组值和逗号之间的缩进被作为空白对待而被忽略。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">integers2</span> = [
</span></span><span style="display:flex;"><span>  <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>, <span style="color:#ae81ff">3</span>
</span></span><span style="display:flex;"><span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">integers3</span> = [
</span></span><span style="display:flex;"><span>  <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#ae81ff">2</span>, <span style="color:#75715e"># 这是可以的</span>
</span></span><span style="display:flex;"><span>]
</span></span></code></pre></div><h3 id="表">表</h3>
<p>表（也被称为哈希表或字典）是键值对的集合。<br>
它们由表头定义，连同方括号作为单独的行出现。<br>
看得出表头不同于数组，因为数组只有值。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">table</span>]
</span></span></code></pre></div><p>在它下方，直至下一个表头或文件结束，都是这个表的键值对。<br>
表不保证保持键值对的指定顺序。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">table-1</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">key1</span> = <span style="color:#e6db74">&#34;some string&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">key2</span> = <span style="color:#ae81ff">123</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">table-2</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">key1</span> = <span style="color:#e6db74">&#34;another string&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">key2</span> = <span style="color:#ae81ff">456</span>
</span></span></code></pre></div><p>表名的规则与键名相同（见前文<a href="#%E9%94%AE%E5%90%8D">键名</a>定义）。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">dog</span>.<span style="color:#e6db74">&#34;tater.man&#34;</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">type</span>.<span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;pug&#34;</span>
</span></span></code></pre></div><p>等价于 JSON 的如下结构：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{ <span style="color:#f92672">&#34;dog&#34;</span>: { <span style="color:#f92672">&#34;tater.man&#34;</span>: { <span style="color:#f92672">&#34;type&#34;</span>: { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;pug&#34;</span> } } } }
</span></span></code></pre></div><p>键名周围的空格会被忽略。<br>
然而，最佳实践还是不要有任何多余的空白。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">a</span>.<span style="color:#a6e22e">b</span>.<span style="color:#a6e22e">c</span>]            <span style="color:#75715e"># 这是最佳实践</span>
</span></span><span style="display:flex;"><span>[ <span style="color:#a6e22e">d</span>.<span style="color:#a6e22e">e</span>.<span style="color:#a6e22e">f</span> ]          <span style="color:#75715e"># 等同于 [d.e.f]</span>
</span></span><span style="display:flex;"><span>[ <span style="color:#a6e22e">g</span> .  <span style="color:#a6e22e">h</span>  . <span style="color:#a6e22e">i</span> ]    <span style="color:#75715e"># 等同于 [g.h.i]</span>
</span></span><span style="display:flex;"><span>[ <span style="color:#a6e22e">j</span> . <span style="color:#e6db74">&#34;ʞ&#34;</span> . <span style="color:#e6db74">&#39;l&#39;</span> ]  <span style="color:#75715e"># 等同于 [j.&#34;ʞ&#34;.&#39;l&#39;]</span>
</span></span></code></pre></div><p>缩进被作为空白对待而被忽略。</p>
<p>你不必层层完整地写出你不想写的所有途径的父表。<br>
TOML 知道该怎么办。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># [x] 你</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># [x.y] 不</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># [x.y.z] 需要这些</span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">x</span>.<span style="color:#a6e22e">y</span>.<span style="color:#a6e22e">z</span>.<span style="color:#a6e22e">w</span>] <span style="color:#75715e"># 来让这生效</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">x</span>] <span style="color:#75715e"># 后置父表定义是可以的</span>
</span></span></code></pre></div><p>空表是允许的，只要里面没有键值对就行了。</p>
<p>类似于键名，你不能重复定义一个表。<br>
这样做是非法的。</p>
<pre tabindex="0"><code># 不要这样做

[fruit]
apple = &#34;红&#34;

[fruit]
orange = &#34;橙&#34;
</code></pre><pre tabindex="0"><code># 也不要这样做

[fruit]
apple = &#34;红&#34;

[fruit.apple]
texture = &#34;光滑&#34;
</code></pre><p>不鼓励无序地定义表。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 有效但不鼓励</span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">apple</span>]
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">animal</span>]
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">orange</span>]
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 推荐</span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">apple</span>]
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">orange</span>]
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">animal</span>]
</span></span></code></pre></div><p>顶层表，又被称为根表，于文档开始处开始并在第一个表头（或文件结束处）前结束。<br>
不同于其它表，它没有名字且无法后置。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#75715e"># 顶层表开始。</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Fido&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">breed</span> = <span style="color:#e6db74">&#34;pug&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 顶层表结束。</span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">owner</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Regina Dogman&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">member_since</span> = <span style="color:#ae81ff">1999-08-04</span>
</span></span></code></pre></div><p>点分隔键为最后一个键名前的每个键名创建并定义一个表，倘若这些表尚未被创建的话。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;red&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 定义一个名为 fruit 的表</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 定义一个名为 fruit.apple 的表</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">taste</span>.<span style="color:#a6e22e">sweet</span> = <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 定义一个名为 fruit.apple.taste 的表</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># fruit 和 fruit.apple 已经创建过了</span>
</span></span></code></pre></div><p>由于表不能定义多于一次，不允许使用 <code>[table]</code> 头重定义这样的表。<br>
同样地，使用点分隔键来重定义已经以 <code>[table]</code> 形式定义过的表也是不允许的。<br>
不过，<code>[table]</code> 形式可以被用来定义通过点分隔键定义的表中的子表。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;红&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">taste</span>.<span style="color:#a6e22e">sweet</span> = <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># [fruit.apple]  # 非法</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># [fruit.apple.taste]  # 非法</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruit</span>.<span style="color:#a6e22e">apple</span>.<span style="color:#a6e22e">texture</span>]  <span style="color:#75715e"># 你可以添加子表</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">smooth</span> = <span style="color:#66d9ef">true</span>
</span></span></code></pre></div><h3 id="内联表">内联表</h3>
<p>内联表提供了一种更为紧凑的语法来表示表。<br>
对于否则就很啰嗦的成组数据，这尤其有用。<br>
内联表被完整地定义在花括号之中：<code>{</code> 和 <code>}</code>。<br>
括号中，可以出现零或更多个以逗号分隔的键值对。<br>
键值对采取与标准表中的键值对相同的形式。<br>
什么类型的值都可以，包括内联表。</p>
<p>内联表得出现在同一行内。<br>
内联表中，最后一对键值对后不允许终逗号（也称为尾逗号）。<br>
不允许花括号中出现任何换行，除非在值中它们合法。<br>
即便如此，也强烈不建议把一个内联表搞成纵跨多行的样子。<br>
如果你发现自己真的需要，那意味着你应该使用标准表。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = { <span style="color:#a6e22e">first</span> = <span style="color:#e6db74">&#34;Tom&#34;</span>, <span style="color:#a6e22e">last</span> = <span style="color:#e6db74">&#34;Preston-Werner&#34;</span> }
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">point</span> = { <span style="color:#a6e22e">x</span> = <span style="color:#ae81ff">1</span>, <span style="color:#a6e22e">y</span> = <span style="color:#ae81ff">2</span> }
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">animal</span> = { <span style="color:#a6e22e">type</span>.<span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;pug&#34;</span> }
</span></span></code></pre></div><p>上述内联表等同于下面的标准表定义：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">name</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">first</span> = <span style="color:#e6db74">&#34;Tom&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">last</span> = <span style="color:#e6db74">&#34;Preston-Werner&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">point</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">x</span> = <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">y</span> = <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">animal</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">type</span>.<span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;pug&#34;</span>
</span></span></code></pre></div><p>内联表是独立自足的，在内部定义全部的键与子表。<br>
不能在括号以外的地方，再添加键与子表。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">product</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">type</span> = { <span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Nail&#34;</span> }
</span></span><span style="display:flex;"><span><span style="color:#75715e"># type.edible = false  # 非法</span>
</span></span></code></pre></div><p>类似地，内联表不能被用于向一个已定义的表添加键或子表。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">product</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">type</span>.<span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Nail&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># type = { edible = false }  # 非法</span>
</span></span></code></pre></div><h3 id="表数组">表数组</h3>
<p>最后一个还没讲到的语法允许你写表数组。<br>
这可以通过把表名写在双方括号里的表头来表示。<br>
表头的第一例定义了这个数组及其首个表元素，而后续的每个则在该数组中创建并定义一个新的表元素。<br>
这些表按出现顺序插入该数组。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[[<span style="color:#a6e22e">products</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Hammer&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sku</span> = <span style="color:#ae81ff">738594937</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">products</span>]]  <span style="color:#75715e"># 数组里的空表</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">products</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;Nail&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">sku</span> = <span style="color:#ae81ff">284758393</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;gray&#34;</span>
</span></span></code></pre></div><p>等价于 JSON 的如下结构。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;products&#34;</span>: [
</span></span><span style="display:flex;"><span>    { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Hammer&#34;</span>, <span style="color:#f92672">&#34;sku&#34;</span>: <span style="color:#ae81ff">738594937</span> },
</span></span><span style="display:flex;"><span>    { },
</span></span><span style="display:flex;"><span>    { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Nail&#34;</span>, <span style="color:#f92672">&#34;sku&#34;</span>: <span style="color:#ae81ff">284758393</span>, <span style="color:#f92672">&#34;color&#34;</span>: <span style="color:#e6db74">&#34;gray&#34;</span> }
</span></span><span style="display:flex;"><span>  ]
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>任何对表数组的引用都指向该数组里最近定义的表元素。<br>
这允许你在最近的表内定义子表，甚至子表数组。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[[<span style="color:#a6e22e">fruits</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;apple&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">fruits</span>.<span style="color:#a6e22e">physical</span>]  <span style="color:#75715e"># 子表</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">color</span> = <span style="color:#e6db74">&#34;red&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">shape</span> = <span style="color:#e6db74">&#34;round&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">fruits</span>.<span style="color:#a6e22e">varieties</span>]]  <span style="color:#75715e"># 嵌套表数组</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;red delicious&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">fruits</span>.<span style="color:#a6e22e">varieties</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;granny smith&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">fruits</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;banana&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[[<span style="color:#a6e22e">fruits</span>.<span style="color:#a6e22e">varieties</span>]]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;plantain&#34;</span>
</span></span></code></pre></div><p>上述 TOML 等价于 JSON 的如下结构。</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;fruits&#34;</span>: [
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;apple&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;physical&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;color&#34;</span>: <span style="color:#e6db74">&#34;red&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;shape&#34;</span>: <span style="color:#e6db74">&#34;round&#34;</span>
</span></span><span style="display:flex;"><span>      },
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;varieties&#34;</span>: [
</span></span><span style="display:flex;"><span>        { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;red delicious&#34;</span> },
</span></span><span style="display:flex;"><span>        { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;granny smith&#34;</span> }
</span></span><span style="display:flex;"><span>      ]
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    {
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;banana&#34;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">&#34;varieties&#34;</span>: [
</span></span><span style="display:flex;"><span>        { <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;plantain&#34;</span> }
</span></span><span style="display:flex;"><span>      ]
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  ]
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>如果一个表或表数组的父级是一个数组元素，该元素必须在定义子级前先定义。<br>
顺序颠倒的行为，必须在解析时报错。</p>
<pre tabindex="0"><code># 非法的 TOML 文档
[fruit.physical]  # 子表，但它应该隶属于哪个父元素？
color = &#34;red&#34;
shape = &#34;round&#34;

[[fruit]]  # 解析器必须在发现“fruit”是数组而非表时抛出错误
name = &#34;apple&#34;
</code></pre><p>若试图向一个静态定义的数组追加内容，即便数组尚且为空，也必须在解析时报错。</p>
<pre tabindex="0"><code># 非法的 TOML 文档
fruits = []

[[fruits]] # 不允许
</code></pre><p>若试图用已经确定为数组的名称定义表，必须在解析时报错。<br>
将数组重定义为普通表的行为，也必须在解析时报错。</p>
<pre tabindex="0"><code># 非法的 TOML 文档
[[fruits]]
name = &#34;apple&#34;

[[fruits.varieties]]
name = &#34;red delicious&#34;

# 非法：该表与之前的表数组相冲突
[fruits.varieties]
name = &#34;granny smith&#34;

[fruits.physical]
color = &#34;red&#34;
shape = &#34;round&#34;

# 非法：该表数组与之前的表相冲突
[[fruits.physical]]
color = &#34;green&#34;
</code></pre><p>你也可以适当使用内联表：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span><span style="color:#a6e22e">points</span> = [ { <span style="color:#a6e22e">x</span> = <span style="color:#ae81ff">1</span>, <span style="color:#a6e22e">y</span> = <span style="color:#ae81ff">2</span>, <span style="color:#a6e22e">z</span> = <span style="color:#ae81ff">3</span> },
</span></span><span style="display:flex;"><span>           { <span style="color:#a6e22e">x</span> = <span style="color:#ae81ff">7</span>, <span style="color:#a6e22e">y</span> = <span style="color:#ae81ff">8</span>, <span style="color:#a6e22e">z</span> = <span style="color:#ae81ff">9</span> },
</span></span><span style="display:flex;"><span>           { <span style="color:#a6e22e">x</span> = <span style="color:#ae81ff">2</span>, <span style="color:#a6e22e">y</span> = <span style="color:#ae81ff">4</span>, <span style="color:#a6e22e">z</span> = <span style="color:#ae81ff">8</span> } ]
</span></span></code></pre></div><h3 id="文件扩展名">文件扩展名</h3>
<p>TOML 文件应当使用 <code>.toml</code> 扩展名。</p>
<h3 id="mime-类型">MIME 类型</h3>
<p>在互联网上传输 TOML 文件时，恰当的 MIME 类型是 <code>application/toml</code>。</p>
<h3 id="abnf-语法">ABNF 语法</h3>
<p>TOML 语法的严谨说明，由一个 <a href="https://github.com/toml-lang/toml/blob/1.0.0/toml.abnf">ABNF 文件</a>另行提供。</p>



          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="my-4 footer">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-sm-12 col-md-6 col-lg-5">
        <div class="mx-0 mx-md-4 mb-2 text-center text-md-start">
          
            <div>
              <a class="mx-1 mr-md-2 ml-md-0 " href="https://beian.miit.gov.cn/">
                
                豫ICP备13005404号
              </a>
            </div>
          

          
            
              <a href="https://www.lyhuilin.com">白菜林</a>
            
          
        </div>
      </div>
      <div class="col-sm-12 col-md-6 col-lg-5">
        <div class="mx-0 mx-md-4 text-center text-md-end">
          

          

          
  <a href="https://github.com/clin003"
     target="_blank"
     class="mx-1 ml-md-2 mr-md-0 icon"
     aria-label="GitHub">

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414">
      <path d="M8 0C3.58 0 0 3.582 0 8c0 3.535 2.292 6.533 5.47 7.59.4.075.547-.172.547-.385 0-.19-.007-.693-.01-1.36-2.226.483-2.695-1.073-2.695-1.073-.364-.924-.89-1.17-.89-1.17-.725-.496.056-.486.056-.486.803.056 1.225.824 1.225.824.714 1.223 1.873.87 2.33.665.072-.517.278-.87.507-1.07-1.777-.2-3.644-.888-3.644-3.953 0-.873.31-1.587.823-2.147-.09-.202-.36-1.015.07-2.117 0 0 .67-.215 2.2.82.64-.178 1.32-.266 2-.27.68.004 1.36.092 2 .27 1.52-1.035 2.19-.82 2.19-.82.43 1.102.16 1.915.08 2.117.51.56.82 1.274.82 2.147 0 3.073-1.87 3.75-3.65 3.947.28.24.54.73.54 1.48 0 1.07-.01 1.93-.01 2.19 0 .21.14.46.55.38C13.71 14.53 16 11.53 16 8c0-4.418-3.582-8-8-8"/>
    </svg>
  </a>


          

          

          

          

          

          
  <a href="mailto:hi@lyhuilin.com"
     class="mx-1 ml-md-2 mr-md-0 icon"
     aria-label="Email">

    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14 16">
      <path d="M0 4v8c0 .55.45 1 1 1h12c.55 0 1-.45 1-1V4c0-.55-.45-1-1-1H1c-.55 0-1 .45-1 1zm13 0L7 9 1 4h12zM1 5.5l4 3-4 3v-6zM2 12l3.5-3L7 10.5 8.5 9l3.5 3H2zm11-.5l-4-3 4-3v6z"/>
    </svg>
  </a>


          <a href=''
   class="mx-1 ml-md-2 mr-md-0 icon"
   aria-label="RSS">

  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414">
    <path d="M12.8 16C12.8 8.978 7.022 3.2 0 3.2V0c8.777 0 16 7.223 16 16h-3.2zM2.194 11.61c1.21 0 2.195.985 2.195 2.196 0 1.21-.99 2.194-2.2 2.194C.98 16 0 15.017 0 13.806c0-1.21.983-2.195 2.194-2.195zM10.606 16h-3.11c0-4.113-3.383-7.497-7.496-7.497v-3.11c5.818 0 10.606 4.79 10.606 10.607z"/>
  </svg>
</a>


          
        </div>
      </div>
    </div>
  </div>
</div>



    <script src="//cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"
            integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
            crossorigin="anonymous"></script>

    

    

    

    
    
  </body>

</html>
